<?php
//
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
if($_RQ['op']=='main'){
	$id=$_RQ['id'];
	if(!$id){
		exi('请选择优惠券','error');
	}
	
	$coupon=pdo_get('jy_weishop_coupon',array('uniacid'=>$_SESSION['uniacid'],'id'=>$id));
	

			$title2 = '';
		$title3 = '';

		if ($coupon['coupontype'] == '0') {
			if (0 < $coupon['enough']) {
				$title2 = '满' . (double) $coupon['enough'] . '元可用';
			}
			else {
				$title2 = '无金额门槛';
			}
		}
		else {
			if ($coupon['coupontype'] == '1') {
				if (0 < $coupon['enough']) {
					$title2 = '充值满' . (double) $coupon['enough'] . '元可用';
				}
				else {
					$title2 = '无金额门槛';
				}
			}
		}

		if ($coupon['coupontype'] == '2') {
			if (0 < $coupon['enough']) {
				$title2 = '满' . (double) $coupon['enough'] . '元可用';
			}
			else {
				$title2 = '无金额门槛';
			}
		}

		if ($coupon['backtype'] == 0) {
			if ($coupon['enough'] == '0') {
				$coupon['color'] = 'orange';
			}
			else {
				$coupon['color'] = 'blue';
			}

			$title3 = '<span class="subtitle nopadding">￥</span>' . (double) $coupon['deduct'];
		}

		if ($coupon['backtype'] == 1) {
			$coupon['color'] = 'red ';
			$title3 = (double) $coupon['discount'] . '折 ';
		}

		if ($coupon['backtype'] == 2) {
			if ($coupon['coupontype'] == '0') {
				$coupon['color'] = 'red ';
			}
			else {
				$coupon['color'] = 'pink ';
			}

			if (!empty($coupon['backmoney']) && (0 < $coupon['backmoney'])) {
				$backmoneytext = $coupon['backmoney'] . '元余额 ';
			}

			if (!empty($coupon['backcredit']) && (0 < $coupon['backcredit'])) {
				$backcredittext = $coupon['backcredit'] . '积分 ';
			}

			if (!empty($coupon['backredpack']) && (0 < $coupon['backredpack'])) {
				$backredpacktext = $coupon['backredpack'] . '元红包';
			}
		}

		$coupon['title2'] = $title2;
		$coupon['title3'] = $title3;
	if($coupon['merch_id']){
		$return['merchneme']=pdo_getcolumn('jy_weishop_merch',array('id'=>$coupon['merch_id']),'title');
	}
	$coupon['limitgoodids']= explode(';', $coupon['limitgoodids']);
	$coupon['limitgoodids']= substr(implode(',', $coupon['limitgoodids']),1,strlen(implode(',', $coupon['limitgoodids']))-2);
	$coupon['limitgoodcateids']= explode(';', $coupon['limitgoodcateids']);
	$coupon['limitgoodcateids']= substr(implode(',', $coupon['limitgoodcateids']),1,strlen(implode(',', $coupon['limitgoodcateids']))-2);
	if ($coupon['limitgoodtype'] != 0) {
			if (!empty($coupon['limitgoodids'])) {
				$where = 'and id in(' . $coupon['limitgoodids'] . ')';
			}

			$goods = pdo_fetchall('select `title` from ' . tablename('jy_weishop_goods') . ' where uniacid=:uniacid ' . $where, array(':uniacid' => $_SESSION['uniacid']), 'id');
		}

		if ($coupon['limitgoodcatetype'] != 0) {
			if (!empty($coupon['limitgoodcateids'])) {
				$where = 'and id in(' . $coupon['limitgoodcateids'] . ')';
			}

			$group = pdo_fetchall('select `title`  from ' . tablename('jy_weishop_goods_group') . ' where uniacid=:uniacid   ' . $where, array(':uniacid' => $_SESSION['uniacid']), 'id');
		}
	$return['setting']=plugin('jy_weishop')->plugin_setting('coupon');
	$return['goods']=$goods;
	$return['group']=$group;
	$return['coupon']=$coupon;
	exi($return);
}

?>